home *** CD-ROM | disk | FTP | other *** search
/ Java Programmer's Toolkit / Java Programmer's Toolkit.iso / hotjava / classsrc / browser / hrtagr~1.jav < prev    next >
Encoding:
Text File  |  1995-08-11  |  2.7 KB  |  109 lines

  1. /*
  2.  * @(#)HRTagRef.java    1.10 95/03/14 Jonathan Payne
  3.  *
  4.  * Copyright (c) 1994 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software
  7.  * and its documentation for NON-COMMERCIAL purposes and without
  8.  * fee is hereby granted provided that this copyright notice
  9.  * appears in all copies. Please refer to the file "copyright.html"
  10.  * for further important copyright and licensing information.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  13.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  14.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  15.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  16.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  17.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  18.  */
  19.  
  20. package browser;
  21.  
  22. import java.util.*;
  23. import java.io.*;
  24. import awt.*;
  25. import net.*;
  26. import net.www.http.*;
  27. import net.www.html.*;
  28.  
  29. /**
  30.  * Class HRTagRef is created for <hr> tags that appear in html
  31.  * document.
  32.  * @version 1.10, 14 Mar 1995
  33.  * @author Jonathan Payne
  34.  */
  35.  
  36. public class HRTagRef extends DisplayItemTagRef {
  37.     static final int    breakHeight = 10;
  38.  
  39.     public HRTagRef(Tag t, int pos, boolean isEnd) {
  40.     super(t, pos, isEnd);
  41.     }
  42.  
  43.     public void buildDisplayItem(WRFormatter f) {
  44.     di = new HRDisplayItem(0);   /* we'll fill in width below */
  45.     }
  46.  
  47.     public void apply(WRFormatter f) {
  48.     if (di == null) {
  49.         buildDisplayItem(f);
  50.     }
  51.     String    widthSpec = getAttribute("width");
  52.     int    width = -1;
  53.  
  54.     f.breakLine(breakHeight);
  55.  
  56.     if (widthSpec != null) {
  57.         int    c;
  58.         int    len = widthSpec.length();
  59.         boolean usePercent = false;
  60.  
  61.         if (len > 0 && widthSpec.charAt(len - 1) == '%') {
  62.         usePercent = true;
  63.         widthSpec = widthSpec.substring(0, len - 1);
  64.         }
  65.         try {
  66.         width = Integer.parseInt(widthSpec);
  67.         if (usePercent) {
  68.             width = (f.win.width * width) / 100;
  69.         }
  70.         } catch (Exception e) {
  71.         }
  72.     }
  73.     if (width <= 0) {
  74.         width = f.win.width - 2 * f.getLeftMargin();
  75.     }
  76.  
  77.     String    align = getAttribute("align");
  78.     if (align != null) {
  79.         if (align.equals("left")) {
  80.         /* remind - how do I know 20? */
  81.         f.setXCoordinate(20);
  82.         } else if (align.equals("center")) {
  83.         f.setXCoordinate((f.win.width - width) / 2);
  84.         } else if (align.equals("right")) {
  85.         f.setXCoordinate(f.win.width - width - 20);
  86.         }
  87.     }
  88.  
  89.     String    sizeString = getAttribute("size");
  90.     int    size = 2;
  91.  
  92.     if (sizeString != null) {
  93.         try {
  94.         size = Integer.parseInt(sizeString);
  95.         } catch (Exception e) {
  96.         }
  97.     }
  98.  
  99.     if (getAttribute("noshade") != null) {
  100.         ((HRDisplayItem) di).shade = false;
  101.     }
  102.  
  103.     di.resize(width, size);
  104.  
  105.     super.apply(f);
  106.     f.breakLine(breakHeight);
  107.     }
  108. }
  109.